﻿Public Class frmHocSinh

    Private Sub ThêmToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ThêmToolStripMenuItem.Click
        Dim frm As frmThemHocSinh = New frmThemHocSinh
        frm.Show()
        Me.Close()
    End Sub

    Private Sub XóaToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles XóaToolStripMenuItem.Click
        Dim dr As DialogResult = New DialogResult
        Try

            If dtgHocSinh.CurrentRow.Cells("ColMaHS").Value.ToString() <> "" Then
                dr = MessageBox.Show("Bạn muốn xóa?", "Delete!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2)
                If dr = DialogResult.Yes Then
                    Dim hs As DAOHocSinh = New DAOHocSinh
                    Dim kq As Boolean = False
                    kq = hs.Delete(Convert.ToInt64(dtgHocSinh.CurrentRow.Cells("ColMaHS").Value), Application.StartupPath + "\database\database.mdb")
                    If kq = True Then
                        LoadAllData()
                    Else
                        MessageBox.Show("Xóa không thành công.", "Lỗi!", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
                        Return
                    End If

                End If
            Else
                MessageBox.Show("Bạn chưa chọn giá trị.")
                Return
            End If
        Catch ex As Exception
            MessageBox.Show("Lỗi", "Lỗi!", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
            Return
        End Try


    End Sub

    Private Sub SửaToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SửaToolStripMenuItem.Click
        Dim hs As DTOHocSinh = New DTOHocSinh
        Try
            If dtgHocSinh.CurrentRow.Cells("ColMaHS").Value.ToString() <> "" Then
                hs.MaHS = Convert.ToInt64(dtgHocSinh.CurrentRow.Cells("ColMaHS").Value)
                hs.TenHS = dtgHocSinh.CurrentRow.Cells("ColTenHS").Value
                hs.TenLop = dtgHocSinh.CurrentRow.Cells("ColTenLop").Value
                hs.GioiTinh = dtgHocSinh.CurrentRow.Cells("ColGioiTinh").Value
                hs.Email = dtgHocSinh.CurrentRow.Cells("ColEmail").Value
                hs.DiaChi = dtgHocSinh.CurrentRow.Cells("ColDiaChi").Value
                hs.NgaySinh = Convert.ToDateTime(dtgHocSinh.CurrentRow.Cells("ColNgaySinh").Value)
                Dim frm As frmThemHocSinh = New frmThemHocSinh(hs)
                frm.ShowDialog()
                Me.Close()
            Else
                MessageBox.Show("Bạn chưa chọn giá trị.", "Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
            End If
        Catch ex As Exception

        End Try

    End Sub

    Private Sub XemĐiểmToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles XemĐiểmToolStripMenuItem.Click
        Dim Ma As Long = 0
        Try
            If dtgHocSinh.CurrentRow.Cells("ColMaHS").Value.ToString() <> "" Then
                Ma = Convert.ToInt64(dtgHocSinh.CurrentRow.Cells("ColMaHS").Value)
                Dim frm As frmXemDiem = New frmXemDiem(Ma)
                frm.Show()
            Else
                MessageBox.Show("Bạn chưa chọn giá trị.")
            End If
        Catch ex As Exception
            MessageBox.Show("Bạn chưa chọn giá trị.")
            Return
        End Try

    End Sub

    Private Sub QuyĐịnhToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles QuyĐịnhToolStripMenuItem.Click
        Dim frm As frmQuyDinh = New frmQuyDinh
        frm.tctQuyDinh.SelectedIndex = 0
        frm.Show()
    End Sub
    Public Sub LoadAllData()
        Dim hs As DAOHocSinh = New DAOHocSinh
        Dim ds As DataTable = New DataTable
        ds = hs.LoadTable("Select * from HocSinh", Application.StartupPath + "\database\database.mdb")
        dtgHocSinh.AutoGenerateColumns = False
        dtgHocSinh.DataSource = ds
    End Sub
    Private Sub frmHocSinh_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LoadAllData()
    End Sub
End Class